﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.HVAC;
using YRevitJig;

namespace YArchitech.Plumbing
{
	public class DrawPipeFromExistJig : PELineJig
	{
		public List<ExistingPipeStruct> ExistPipeStructs { get; set; }

		public double? SettingDistance { get; set; }

		public DeriPipeOffSet DeriPipeOffSet { get; set; }

		public DrawPipeFromExistJig(UIDocument uiDoc) : base(uiDoc)
		{
			base.JigStage = PELineJig.EStage.eNoOper;
			base.ResetPoint = XUiJigBase.EResetPoint.eByAxis;
		}

		public override void Draw(PaintEventArgs paintEventArgs)
		{
			base.Draw(paintEventArgs);
			if (!this.m_ptCur.IsEmpty && base.JigStage == PELineJig.EStage.eEndPt)
			{
				XYZ xyz = base.Client2Revit(this.m_ptCur);
				XYZ currentPoint = xyz;
				if (base.ResetPoint == XUiJigBase.EResetPoint.eByAngle)
				{
					XYZ projectPoint = JigFuncs.GetProjectPoint(base.UiDoc, xyz, base.StartPoint, base.LineAngle);
					this.m_ptCur = base.Revit2Client(projectPoint);
				}
				else if (base.ResetPoint == XUiJigBase.EResetPoint.eByOrtho)
				{
					XYZ orthoPoint = JigFuncs.GetOrthoPoint(base.UiDoc, xyz, base.StartPoint);
					this.m_ptCur = base.Revit2Client(orthoPoint);
				}
				else if (base.ResetPoint == XUiJigBase.EResetPoint.eByAxis)
				{
					XYZ axisPoint = JigFuncs.GetAxisPoint(base.UiDoc, xyz, base.StartPoint);
					if (axisPoint != null)
					{
						currentPoint = axisPoint;
					}
				}
				this.PipeLines = DrawMultiPipeUtility.DrawMutilFromExistingPipes(this.ExistPipeStructs, base.StartPoint, currentPoint, this.DeriPipeOffSet, this.SettingDistance);
				XGraphics g = new XGraphics(paintEventArgs.Graphics, base.JigPen);
				foreach (List<LineInfo> list in this.PipeLines)
				{
					foreach (LineInfo lineInfo in list)
					{
						new XLine2D(base.Revit2Client(lineInfo.StartPoint), base.Revit2Client(lineInfo.EndPoint)).Draw(g);
					}
				}
			}
		}

		private System.Drawing.Point Revit2Client()
		{
			throw new NotImplementedException();
		}

		public List<List<LineInfo>> PipeLines = new List<List<LineInfo>>();
	}
}
